package org.edu.modules.common.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.edu.common.util.PasswordUtil;
import org.edu.common.util.oConvertUtils;
import org.edu.modules.common.entity.VeBaseAppUser;
import org.edu.modules.common.mapper.VeBaseAppUserMapper;
import org.edu.modules.common.service.IVeBaseAppUserService;
import org.edu.modules.common.vo.VoAppUserBySearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Auther 李少君
 * @Date 2021-12-13 16:23
 */
@Service
public class VeBaseAppUserServiceImpl extends ServiceImpl<VeBaseAppUserMapper, VeBaseAppUser> implements IVeBaseAppUserService {

    @Autowired
    private VeBaseAppUserMapper veBaseAppUserMapper;

    @Override
    public int updateAppUserPasswordById(String pwd, String strength, String id) {

        return veBaseAppUserMapper.updateAppUserPasswordById(pwd, strength, id);
    }

    @Override
    public int addSysUser(VeBaseAppUser veBaseAppUser) {

        return veBaseAppUserMapper.addSysUser(veBaseAppUser);
    }

    @Override
    public VeBaseAppUser getPwdAndSalt(VeBaseAppUser veBaseAppUser) {
        String salt = oConvertUtils.randomGen(8);
        String passwordEncode = PasswordUtil.encrypt(veBaseAppUser.getUserName(), veBaseAppUser.getUserPassword(), salt);
        veBaseAppUser.setUserPassword(passwordEncode);
        veBaseAppUser.setSalt(salt);
        return veBaseAppUser;
    }

    @Override
    public String pwdVerify(String pwd) {
        int flag = 0;
        if (pwd.matches(".*[0-9].*")) {
            flag++;
        }
        if (pwd.matches(".*[a-z].*")) {
            flag++;
        }
        if (pwd.matches(".*[A-Z].*")) {
            flag++;
        }
        if (pwd.matches(".*[!@*#$\\-_()+=&￥].*")) {
            flag++;
        }
        if (flag == 1) {
            return "弱";
        }
        if (flag == 2) {
            return "中";
        }
        return "强";
    }

    @Override
    public Integer getIdByRoleCode(String code) {

        return veBaseAppUserMapper.getIdByRoleCode(code);
    }

    @Override
    public VeBaseAppUser getAppUserByUserId(String userId) {

        return veBaseAppUserMapper.getAppUserByUserId(userId);
    }

    @Override
    public Map getSysRoleUser(String userId, Integer roleId) {

        return veBaseAppUserMapper.getSysRoleUser(userId, roleId);
    }

    @Override
    public int addSysRoleUser(String userId, Integer roleId) {

        return veBaseAppUserMapper.addSysRoleUser(userId, roleId);
    }

    @Override
    public List<Map<String, Object>> queryOrganUserTreeList(String paramString) {

        return null;
    }

    @Override
    public List<Map<String, Object>> getAppUserBySearch(VoAppUserBySearch voAppUserBySearch) {
        return veBaseAppUserMapper.getAppUserBySearch(voAppUserBySearch);
    }

    @Override
    public int updateAppUserByUserId(String userId) {
        return veBaseAppUserMapper.updateAppUserByUserId(userId);
    }

    @Override
    public int updateSysUserDel(String userId) {
        return veBaseAppUserMapper.updateSysUserDel(userId);
    }
    @Override
    public int deleteSysUser(String userId) {
        return veBaseAppUserMapper.deleteSysUser(userId);
    }
    @Override
    public int updateSysUserDelBatch(List<String> userIds) {
        return veBaseAppUserMapper.updateSysUserDelBatch(userIds);
    }

    @Override
    public int deleteOrgan(String userId) {
        return veBaseAppUserMapper.deleteOrgan(userId);
    }

    @Override
    public int deleteRole(String userId) {
        return veBaseAppUserMapper.deleteRole(userId);
    }
    @Override
    public int deleteRole(String userId,Integer roleId) {
        return veBaseAppUserMapper.deleteRole2(userId,roleId);
    }

    @Override
    public List<Map<String, Object>> queryResourcePageList() {
        return veBaseAppUserMapper.queryResourcePageList();
    }

    @Override
    public IPage<Map<String, Object>> getDataListByTableName(Page paramPage, String paramString) {
        return veBaseAppUserMapper.getDataListByTableName(paramPage, paramString);
    }

    @Override
    public List<Map<String, Object>> queryColumnNameListByTableName(String tableName) {
        return veBaseAppUserMapper.queryColumnNameListByTableName(tableName);
    }

    @Override
    public List<Map<String, Object>> querySysRoleList() {
        return veBaseAppUserMapper.querySysRoleList();
    }

    @Override
    public List<Map<String, Object>> queryAppUserTeacherList() {
        return veBaseAppUserMapper.queryAppUserTeacherList();
    }

    @Override
    public int stopAppUserByUserId(String userId) {
        return veBaseAppUserMapper.stopAppUserByUserId(userId);
    }

    @Override
    public List<Map<String, Object>> queryAppManageList() {
        return veBaseAppUserMapper.queryAppManageList();
    }

    @Override
    public List<Map<String, Object>> getUnreadMessageCountUserId() {
        return veBaseAppUserMapper.getUnreadMessageCountUserId();
    }

    @Override
    public List<Map<String, Object>> queryAppUserListByRoleId(Integer roleId) {
        return veBaseAppUserMapper.queryAppUserListByRoleId(roleId);
    }
}
